<?php

class SQL
{
	private static $_error;
	private static $_thread;
	private static $_cache;
	private static $_connection;
	public static function connect($host, $user, $password, $db)
	{
		self::$_connection=mysql_connect($host, $user, $password);
		if(!self::$_connection)
		{
			throw new SQLException("Nem lehet csatlakozni az adatbázishoz!", mysql_error());
		}
		if(!mysql_select_db($db))
		{
			throw new SQLException("Nem tudom az adatbázist kiválasztani!", mysql_error());
		}
		
		self::$_thread=array();
		self::$_error=array();
		self::$_cache=array();
	}
	public static function query($cmd, $thread=0)
	{
		self::$_thread[$thread]=mysql_query($cmd);
		if(mysql_error())
		{
			self::$_error[]=array("error"=>mysql_error(), "query"=>$cmd);
		}
	}
	public static function fetch($cmd, $thread=0)
	{
		self::query($cmd, $thread);
		return mysql_fetch_assoc(self::$_thread[$thread]);
	}
	public static function fetchAll($cmd, $thread=0)
	{
		self::query($cmd, $thread);
		$result=array();
		while(($row=mysql_fetch_assoc(self::$_thread[$thread]))!==false)
		{
			$result[]=$row;
		}
		return $result;
	}
}
		